package cn.itcast.nems.enrol.service.impl;

import cn.itcast.nems.enrol.converter.ActivityCourseConverter;
import cn.itcast.nems.enrol.dao.dataobject.ActivityCourseDO;
import cn.itcast.nems.enrol.dao.mapper.ActivityCourseMapper;
import cn.itcast.nems.enrol.dto.ActivityCourseDTO;
import cn.itcast.nems.enrol.service.ActivityCourseService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * author liyong
 * create: 2024-04-16 16:00:24
 **/
@Service
public class ActivityCourseServiceImpl implements ActivityCourseService {
    private final ActivityCourseMapper activityCourseMapper;

    public ActivityCourseServiceImpl(ActivityCourseMapper activityCourseMapper) {
        this.activityCourseMapper = activityCourseMapper;
    }

    @Override
    public List<ActivityCourseDTO> findActivityCourses(String activityCode) {
        final List<ActivityCourseDO> courses = this.activityCourseMapper.selectActivityCourses(activityCode);
        if (!courses.isEmpty()) {
            return courses.stream().map(ActivityCourseConverter::doToDTO).toList();
        }
        return List.of();
    }

    @Override
    public ActivityCourseDTO findActivityCourse(String schoolId, String subjectId) {
        final ActivityCourseDO courseDO = this.activityCourseMapper.selectActivityCourse(schoolId, subjectId);
        return ActivityCourseConverter.doToDTO(courseDO);
    }

}
